<style>
.list:hover{ background: #FDFFD5 !important; }
</style>
<form class="form_style registed" style="margin-top:0px;">
    <div style="display:block;float:left;width:250px">
    	<input id="rsearch" type="text" placeholder="Search..." style="width:94%" />
    	<table>
    		<thead>
    			<tr style="display:block;position:relative;">
    				<th style="width: 310px;">Result</th>
    			</tr>
    		</thead>
    		<tbody id="rsearchresult" style="height: 210px;overflow: auto;display: block;width:100%">
    		</tbody>
    	</table>
    </div>
	<div style="display:block;float:right;width:250px">
    	<strong>Item Name :</strong>
    	<br />
    	<input name="returnitem" type="text" style="width:94%;" disabled />
    	<strong>Returned by :</strong>
    	<br />
    	<input name="returnby" type="text" style="width:94%" />
    	<strong>Quantity :</strong>&nbsp;
    	<input name="returnqty" type="text" style="width:30%" value="0" />
    	<br />
    	<strong>Reason :</strong>
    	<br />
    	<textarea name="returnreason" class="ease" style="max-height:100px;max-width:235px;min-width:235px;min-height:100px;"></textarea>
    	<br />
	</div>
	<div class="clear"></div>
	<hr style="margin-bottom:10px;margin-top:10px" />
	<input name="returnitemsaving" type="button" style="float:right;" value="Save" disabled />
	<div class="clear"></div>
</form>
<script>
	$('#rsearch').keyup(function(){
        $.post('?module=pos&action=inventory&action2=return&ajax=true', {key:$(this).val(), search:1}, function(data) {
    		$('#rsearchresult').hide().fadeIn('slow').html(data);
			$('#rsearchresult tr').dblclick(function(){
				var id = $(this).attr('iid');
				var name = $(this).children().text();
				$('input[name=returnitem]').val(name).attr('iid',id);
				$('input[name=returnitemsaving]').attr('disabled',false);
				$('#rsearch').val('');
			}) 
        });	
	});
	$('input[name=returnitemsaving]').click(function(){
		var id = $('input[name=returnitem]').attr('iid');
		if($(this).attr('disabled') || id.length == 0)
			return;
		var reason = $('textarea[name=returnreason]').val();
		var name = $('input[name=returnby]').val();
		var qty = $('input[name=returnqty]').val();
		if( reason.length == 0 || name.length == 0 || isNaN(qty) || qty*1 < 1){
			alert('Name, quantity and reason are required.');
			return;
		}
		$.post('?module=pos&action=inventory&action2=return&ajax=true', {id:id, reason:reason, name:name, qty:qty, save:1}, function() {
			$('input[name=returnitemsaving]').attr('disabled', true);
			$('input[name=returnitem]').attr('iid','').val('');
			$('textarea[name=returnreason]').val('');
			$('input[name=returnby]').val('');
			$('input[name=returnqty]').val('0');
		});
	});
	$('#rsearch').val(' ');
	$('#rsearch').trigger('keyup');
	$('#rsearch').val('');
</script>